package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 商家错误异常枚举类
 */
public enum ShopException implements IntegerEnum<Integer> {

    ACCOUNT_AUDIT_PASS(50101, "该会员已审核通过，请勿重复申请！！！"),
    ACCOUNT_AUDIT_WAIT(50102, "该会员正在审核中，请勿重复申请！！！"),
    SHOP_NOT_EXIST(50103, "该商家不存在！！！"),
    SHOP_ALLOCATED(50104, "该商家已分配管理员账号！！！"),
    SHOP_ALREADY_INIT(50105, "已初始化过店铺"),
    LON_AND_LAT_NOT_EXIST(50106, "经纬度不能为空"),
    SHOP_WITHDRAW_INSUFFICIENT_FUND(50107, "商家提现金额不足"),
    SHOP_OPERATION(50108, "商家才能操作"),
    NOWADAY_SHOP_NOT_OPERATION(50109, "当前商家不能操作"),
    SHOP_APPLY_NOT_EXIST(50109, "商家审核记录不存在"),
    PT_SHOP_NOT_EXIST(50110, "平台店铺不存在"),
    SHOP_UPDATE_AUDIT_WAIT(50111, "您的商家修改申请正在待审核，请耐心等待..."),
    MUST_PARAMETER_NOT_NULL(50112, "必要参数不能为空"),
    SHOP_UPDATE_NOT_EXIST(50113, "商家修改记录不存在"),
    SHOP_UPDATE_COMPLETE_NOT_DEL(50114, "该商家审核已完成，不能删除"),

    SHOP_ID_NOT_EXIST(50104, "该商家ID不存在！！！"),
    ;

    private Integer code;

    private String msg;

    ShopException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    @Override
    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @JsonCreator
    public static ShopException getByCode(int code) {
        for (ShopException value : ShopException.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
